//
//  WbUserInfoModel.swift
//  Weibo
//
//  Created by HH on 16/12/4.
//  Copyright © 2016年 Weibo. All rights reserved.
//

import UIKit

class WbUserInfoModel: NSObject,NSCoding {
    
    var access_token:String?
    
    var uid:Int64 = 0
    
    var expires_in:TimeInterval = 0{
        didSet {
            
            expiresDate = Date().addingTimeInterval(expires_in)
        }
    }
    
    //  用户的名字
    var name: String?
    //  用户的头像
    var avatar_large: String?
    //过期日期
    var expiresDate:Date?
    
    override init() {
        super.init()
    }
    
    func encode(with aCoder: NSCoder) {
        return yy_modelEncode(with: aCoder)
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        super.init()
        
        yy_modelInit(with: aDecoder)
        
    }

}

extension WbUserInfoModel{
    
    func saveUserInfo(){
        
        let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! as NSString).appendingPathComponent("userAccount.archive")
        
        NSKeyedArchiver.archiveRootObject(self, toFile: path)
        
    }
    
    class func loadUserInfo()->WbUserInfoModel?{
        
        let path = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! as NSString).appendingPathComponent("userAccount.archive")
        
        let userInfo = NSKeyedUnarchiver.unarchiveObject(withFile: path)
        
        
        return userInfo as? WbUserInfoModel
        
        
    }
    
}
